package day230411;

import java.util.Scanner;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/4/12 15:36
 * 求两个字符串的公共子串的最大长度
 */
public class Main02 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextLine()) {
            String str1 = scan.nextLine();
            String str2 = scan.nextLine();
            int len = getLongestSubstrLen(str1, str2);
            System.out.println(len);
        }
        scan.close();
    }

    private static int getLongestSubstrLen(String str1, String str2) {
        if (str1.length() < str2.length()) {
            String temp = str1;
            str1 = str2;
            str2 = temp;
        }
        // 动态规划
        int maxLen = 0; // 存储最大长度
        int[][] dp = new int[str1.length() + 1][str2.length() + 1];
        for (int i = 1; i <= str1.length(); i++) {
            for (int j = 1; j <= str2.length(); j++) {
                if (str1.charAt(i-1) == str2.charAt(j-1)) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    maxLen = Math.max(dp[i][j], maxLen);
                } else {
                    dp[i][j] = 0;
                }
            }
        }
        return maxLen;
    }
}
